home *** CD-ROM | disk | FTP | other *** search
- Path: news.dal.ca!news
- From: Klaus.Eichele@Dal.Ca (Klaus Eichele)
- Newsgroups: comp.lang.c++
- Subject: Re: BC 3.1 - 4.5 (error!?)
- Date: Wed, 17 Apr 1996 01:53:05 GMT
- Organization: Dalhousie University
- Message-ID: <4l14s3$lg1@News.Dal.Ca>
- References: <3173D628.48F6@demos.su>
- NNTP-Posting-Host: rewasylishen.chem.dal.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- Alexey Ruzin <00alex@demos.su> wrote:
-
- >Hi, All
-
- >Here is simple example of abnormal programming.
- >But BC crashed (sorry, it works and even compiles
- >the program, but it is unpredictable what will occur)
- >on it:
-
- >#include <stdio.h>
-
- >int st_func( int a )
- >{
- > static int p=a;
- > return p++;
- >}
-
- >int main( int argc, char *argv[] )
- >{
- > int i;
- > if( argc != 1 )
- > {
- > for( i = 10; i>0; i-- )
- > printf( "%d\n", st_func( i ) );
- > }
- > else
- > {
- > for( i = 0; i<10; i++ )
- > printf( "%d\n", st_func( i ) );
- > }
- > return 0;
- >}
-
- >Enjoy...
-
- >If you know what is wrong reply please :)
-
- Hi,
- I am not sure what this program is supposed to achieve, but compiling
- it sure produces an error: illegal initialization.
- > static int p=a;
- The reason is that at initialization time a is (or would be)
- undefined. If you want your function to work, you will need to change
- it to:
-
- int st_func( int a )
- {
- static int p;
- p=a;
- return p++;
- }
-
- Good Luck,
- Klaus
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Klaus Eichele keichele@is.dal.ca
- http://is.dal.ca/~keichele/keichele.html
-
-